//
//  UIImage+SizeExtension.swift
//  选取相册
//
//  Created by 刘健 on 16/4/4.
//  Copyright © 2016年 Clemmie. All rights reserved.
//

import UIKit

extension UIImage {
    
    
    func changeImageSize(newSizeW: CGFloat = 300) -> UIImage {
        if self.size.width < newSizeW {
            return self
        }
        
        //算出等比例新高度
//        sizeW:sizeH = newSizeW : newSizeH
       let newSizeH = self.size.height * newSizeW / self.size.width
        
       let newSize = CGSize(width: newSizeW, height: newSizeH)
        
        //绘制上下文
        UIGraphicsBeginImageContext(newSize)
        
        drawInRect(CGRect(origin: CGPointZero, size: newSize))
        
        let image = UIGraphicsGetImageFromCurrentImageContext()
        
        UIGraphicsEndImageContext()
       
        return image
    }
}
